package com.lemei.cn.lemeiapp;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.lemei.cn.utils.ToastMake;

/**
 * Created by 赵航 on 2017/5/26.
 */

public class BasicActivity extends AppCompatActivity {
    private ProgressDialog    mProgressDialog;
    private SharedPreferences mSP;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化进度条对话框
        mProgressDialog = new ProgressDialog(BasicActivity.this);
        //设置进度条对话框不可取消
        mProgressDialog.setCancelable(false);
        mSP = getSharedPreferences("config", MODE_PRIVATE);

        //将当前Activity放到Application的集合中
        //        LeMei application = (LeMei) getApplication();
        //        application.addActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //将当前Activity从Application的集合中移除
        //        LeMei application = (LeMei) getApplication();
        //        application.removeActivity(this);
    }

    public void saveUser(String username, String pwd) {
        mSP.edit()
                .putString("username", username)
                .putString("pwd", pwd)
                .commit();
    }

    public String getUsername() {
        return mSP.getString("username", "");
    }

    public String getPwd() {
        return mSP.getString("pwd", "");
    }

    public void showDialog(String msg) {
        mProgressDialog.setMessage(msg);
        mProgressDialog.show();
    }

    public void hideDialog() {
        mProgressDialog.dismiss();
    }

    public void showToast(String msg) {
        ToastMake.showToast(msg);
    }

    public void startActivity(Class clazz, boolean isFinish) {

        startActivity(new Intent(this, clazz));
        if (isFinish) {
            finish();
        }
    }

}
